<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>解构赋值</title>
</head>
<body>
    <div></div>
    <script>
        //1、数据交换
        let a = 1;
        let b = 2;

        //es5
        // var temp = a;
        // a = b;
        // b = temp;
        // console.log(a,b)

        //es6
        [a,b] = [b,a]
        console.log(a,b)

        //2、提取json
        let json ={
            id:1,
            status:'ok',
            data:[1001,1002]
        };

        //通常写法
        var id = json.id;
        var status = json.status;
        var data = json.data;

        //es6
        let {id,status,data} = json;
        console.log(id)
        console.log(status)
        console.log(data)
    </script>
</body>
</html>